package com.zhz.mall.common.annotation;


import com.zhz.mall.common.util.enums.EnumValueResolver;
import com.zhz.mall.common.constraints.ValueContainsValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 值存在
 *
 * @author  zhouhengzhe
 * @version 1.0.0
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(ValueContains.List.class)
@Documented
@Constraint(validatedBy = ValueContainsValidator.class)
public @interface ValueContains {

    String message() default "{com.zhz.mall.common.annotation.ValueContains}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    Class<? extends EnumValueResolver<?, ?>> scopeEnum();

    /**
     * 是否判断枚举的value值，
     * true-> {@link EnumValueResolver#getValue()}
     * fale -> {@link EnumValueResolver#getDesc()}
     *
     * @return 默认和为true
     */
    boolean isFromValue() default true;

    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface List {

        ValueContains[] value();
    }
}
